package logic

import (
	"context"
	"fmt"
	"good_srv/good"
	"good_srv/internal/svc"
	"good_srv/models"
	"gorm.io/gorm"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateUserLogic {
	return &UpdateUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改头像上传、昵称修改、联系方式
func (l *UpdateUserLogic) UpdateUser(in *good.UpdateUserRequest) (*good.UpdateUserResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	users := models.User{
		Model: gorm.Model{
			ID: uint(in.UserId),
		},
		Phone:    in.Phone,
		Image:    in.Image,
		NickName: in.Nickname,
	}
	if err = users.Update(); err != nil {
		logx.Error("个人信息完善失败")
		return nil, fmt.Errorf("个人信息完善失败")
	}
	return &good.UpdateUserResponse{
		Image:    users.Image,
		Nickname: users.NickName,
		Phone:    users.Phone,
		UserId:   int64(users.ID),
	}, nil
}
